
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改账号</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
    <script src="/public/js/selectIframe.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div style="height: 42px;line-height: 42px;padding: 0 15px;border-bottom: 1px solid #f6f6f6;color: #333;border-radius: 2px 2px 0 0;font-size: 14px;">
            <span><i id="return" class="layui-icon layui-icon-return" style="padding-right: 10px;"></i></span>
            <span>修改账号</span>
        </div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="component-form-group">
                <input type="hidden" name="id" value="${sysAdminDto?.id}">

                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" value="${sysAdminDto?.name?.raw()}" style="width: 300px" lay-verify="required" autocomplete="off" placeholder="请输入姓名" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">账号角色</label>
                    <div class="layui-input-inline" style="width: 200px;">
                        <select class="layui-input" name="roleId" lay-verify="required">
                            <option value="">请选择账号角色</option>
                        #{if roleList != null}
                            #{list items:roleList?.list,as:'role'}
                                #{if role?.get('id')?.getAsInt() == sysAdminDto?.roleId}
                                    <option value="${role.get('id').getAsInt()}" selected="selected">${role.get('name').getAsString()?.raw()}</option>
                                #{/if}
                                #{else}
                                    <option value="${role.get('id').getAsInt()}">${role.get('name').getAsString()?.raw()}</option>
                                #{/else}
                            #{/list}
                        #{/if}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">关联站点</label>
                        <div class="layui-input-inline" style="width: 600px">
                            <input type="text" id="stationName" name="stationName" autocomplete="off" placeholder="请选择站点" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <input type="button" class="layui-btn layui-btn-normal layui-btn-radius" onclick="selectStation()" value="关联站点">
                        </div>
                        <input type="hidden" name="stationId" id="stationId" value="">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">已关联站点</label>
                    <div class="layui-input-inline" style="top: 8px;width: 800px" id="stationList">
                    #{if sysAdminDto?.stationName!=null && sysAdminDto.stationName.size()>0}
                        #{list items:sysAdminDto?.stationName,as:'station'}
                            <span class="layui-badge layui-bg-green">${station?.get("name")?.getAsString()?.raw()}</span>
                            <i class="layui-icon layui-icon-delete" title="删除站点" id="${station?.get("adminStationId")?.getAsString()}"></i>&nbsp;&nbsp;&nbsp;&nbsp;
                        #{/list}
                    #{/if}
                    </div>
                </div>

                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="/public/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/public/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','layer'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,layer = layui.layer
            ,form = layui.form;

        $(document).on('click','#return',function(){
            window.location.href = "/sys/userList";
        });

        //删除站点
        $("#stationList").on("click",".layui-icon.layui-icon-delete",function () {
            var adminStationId=this.id;
            layer.confirm('真的删除这个站点么', {icon: 7, title: '提示', skin: 'layui-layer-molv', anim: 4}, function (index) {
                layer.close(index);
                $.get("/sys/deleteAdminStation?adminStationId=" + adminStationId, function (result) {
                    if (result.code > 0) {
                        layer.msg(result.msg, {icon: 2});
                        return false;
                    } else {
                        layer.msg(result.msg, {time: 2000}, function () {
                            window.location.reload();
                        });
                    }
                });
            });
        });

        /* 监听提交 */
        form.on('submit(component-form-demo1)', function(data){
            var data=data.field;
            $.post("/sys/saveUser", data, function (result) {
                if (result.code > 0) {
                    layer.msg(result.msg, {icon:2});
                } else {
                    window.location.href = "/sys/userList";
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
